# -*-coding: utf-8 -*-
# İhtimal modülü
 # Copyright (C) 2008, Oğuzhan Eroğlu <oguzhan@oguzhaneroglu.com>
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.

 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.

__author__ = "Oğuzhan Eroğlu <oguzhan@oguzhaneroglu.com>"
__version__ = "0.1"

import random as random_

def random(dict):
	randomList = []

	# check %
	imp = 0
	for i in dict.keys():
		imp += dict[i];

	if imp != 100:
		raise ValueError, "Tüm ihtimallerin toplamı 100 değil!"

	for i in dict.keys():
		for c in range(dict[i]):
			randomList.append(i)

	return random_.choice(randomList)

class probability:
    def __init__(self, prePro={}):
	self.probs = {}
	for i in prePro.keys():
	    self.probs[i] = prePro[i]

    def add(self, key, value):
	self.probs[key] = value

    def addDict(self, dict):
	for i in dict.keys():
	    self.probs[i] = dict[i]

    def random(self):
	return random(self.probs)
